package com.example.dubbo.controller;

import com.example.dubbo.pojo.Mail;
import com.example.dubbo.service.ProviderService;
import com.example.dubbo.service.SimpleSendEmail;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;

/**
 * @author: trtan
 * @date: 2021-06-15 16:25
 **/
@RestController
public class HelloController {
    @Reference
    ProviderService providerService;

    @Reference
    SimpleSendEmail simpleSendEmail;

    @RequestMapping("/hello/{name}")
    public String hello(@PathVariable("name") String name) {
        return providerService.sayHello(name);
    }

    @RequestMapping("/send/{valid}")
    public String send(@PathVariable("valid") String valid) {
        if (valid.equals("123")) {
            Mail mail = new Mail();
            mail.setEmail("xxxx");
            mail.setSubject("Springboot邮件发送测试");
            mail.setMsg("发送成功");
            simpleSendEmail.send(mail);
            return "success";
        }
        return "发送失败！";
    }
}
